package com.muyu.product.domain;

import java.math.BigDecimal;
import java.util.function.Supplier;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.product.domain.model.ProjectSkuModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import io.swagger.annotations.*;
import com.muyu.common.core.annotation.Excel;
import com.muyu.product.domain.req.ProjectSkuInfoQueryReq;
import com.muyu.product.domain.req.ProjectSkuInfoSaveReq;
import com.muyu.product.domain.req.ProjectSkuInfoEditReq;
import com.muyu.common.core.web.domain.BaseEntity;

/**
 * 商品SKU对象 project_sku_info
 *
 * @author DongZeLiang
 * @date 2024-02-27
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("project_sku_info")
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ProjectSkuInfo", description = "商品SKU")
public class ProjectSkuInfo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /** 主键 */
    @TableId(value = "id",type = IdType.AUTO)
    @ApiModelProperty(name = "主键", value = "主键")
    private Long id;

    /** 商品id */
    @Excel(name = "商品id")
    @ApiModelProperty(name = "商品id", value = "商品id", required = true)
    private Long projectId;

    /** sku */
    @Excel(name = "sku")
    @ApiModelProperty(name = "sku", value = "sku", required = true)
    private String sku;

    /** 商品库存 */
    @Excel(name = "商品库存")
    @ApiModelProperty(name = "商品库存", value = "商品库存", required = true)
    private Long stock;

    /** 商品价格 */
    @Excel(name = "商品价格")
    @ApiModelProperty(name = "商品价格", value = "商品价格", required = true)
    private BigDecimal price;

    /** 规格图片 */
    @Excel(name = "规格图片")
    @ApiModelProperty(name = "规格图片", value = "规格图片", required = true)
    private String image;

    /**
    * 查询构造器
    */
    public static ProjectSkuInfo queryBuild( ProjectSkuInfoQueryReq projectSkuInfoQueryReq){
        return ProjectSkuInfo.builder()
                .projectId(projectSkuInfoQueryReq.getProjectId())
                .sku(projectSkuInfoQueryReq.getSku())
                .stock(projectSkuInfoQueryReq.getStock())
                .price(projectSkuInfoQueryReq.getPrice())
                .image(projectSkuInfoQueryReq.getImage())
                .build();
    }

    /**
    * 添加构造器
    */
    public static ProjectSkuInfo saveBuild(ProjectSkuInfoSaveReq projectSkuInfoSaveReq){
        return ProjectSkuInfo.builder()
                .projectId(projectSkuInfoSaveReq.getProjectId())
                .sku(projectSkuInfoSaveReq.getSku())
                .stock(projectSkuInfoSaveReq.getStock())
                .price(projectSkuInfoSaveReq.getPrice())
                .image(projectSkuInfoSaveReq.getImage())
                .build();
    }

    /**
    * 修改构造器
    */
    public static ProjectSkuInfo editBuild(Long id, ProjectSkuInfoEditReq projectSkuInfoEditReq){
        return ProjectSkuInfo.builder()
            .id(id)
                .projectId(projectSkuInfoEditReq.getProjectId())
                .sku(projectSkuInfoEditReq.getSku())
                .stock(projectSkuInfoEditReq.getStock())
                .price(projectSkuInfoEditReq.getPrice())
                .image(projectSkuInfoEditReq.getImage())
                .build();
    }

    /**
     *
     * @param projectSkuModel
     * @return
     */
    public static ProjectSkuInfo productSkuModelBuild(ProjectSkuModel projectSkuModel, Supplier<Long> projectId){
        return ProjectSkuInfo.builder()
                .projectId(projectId.get())
                .sku(projectSkuModel.getSku())
                .image(projectSkuModel.getImage())
                .stock(projectSkuModel.getStock())
                .build();
    }

}
